/*
 * glob_example.c: Do some stuff with globs.
 */
#include <sharp-glob.h>

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    /* Compile a pattern first. This step actually does nothing (refer to the
     * documentation), but for completeness' sake, we do it anyway.
     */
    sharp_glob ban = sharp_glob_compile("*x!~c*@local*");

    /* If the ban pattern matches the host culex!~culex@localghost, show so! */
    if(sharp_glob_match(ban, "culex!~culex@localghost"))
        printf("%s\n", "You're banned, fool!");
    else
        printf("%s\n", "Nothing to see here, move along.");

    /* This is supposed to catch both epic win and epic fail. */
    sharp_glob testing = sharp_glob_compile("epic ???*");
    if(sharp_glob_match(testing, "epic win"))
        printf("%s\n", "Yo, we're winning, bro.");
    else
        printf("%s\n", "This isn't exactly the kind of fail I had in mind...");

    if(sharp_glob_match(testing, "epic fail"))
        printf("%s\n", "Set sail for phail");
    else
        printf("%s\n", "Oh no, li'l bro, you killed ABOBO.");

    /* Now to see if we can find this in a haystack. */
    printf("%s\n", sharp_glob_find(testing,
                "Will this be as epic win as I imagine it to be?"));

    /* This should return "(null)" */
    // XXX: gcc hack; seems to break on %s\n, so we'll add a space in front
    printf("%s \n", sharp_glob_find(testing, "Not so epic, now is it?"));

    return EXIT_SUCCESS;
}

